// 上传菜品图片
const express = require('express')
const router = express.Router()
const multer = require('multer')
// const bodyParser = require('body-parser')
const fs = require('fs')
const baseURL = 'http://localhost:5000/uploads'

/* GET organ page. */
router.post(
  '/Cuisine/upload',
  multer({
    dest: 'uploads/Cuisine',
  }).array('file'),
  (req, res) => {
    const files = req.files
    const fileList = []
    console.log(fileList,"菜品图片")
    for (var i in files) {
      var file = files[i]
      fs.renameSync(file.path, `uploads/Cuisine/${file.filename}.jpg`)
      file.path = `${baseURL}/Cuisine/${file.filename}.jpg`
      fileList.push(file)
    }
    res.send(fileList)
  }
)

router.post(
  '/Seller/upload',
  multer({
    dest: 'uploads/Seller',
  }).array('file'),
  (req, res) => {
    const files = req.files
    const fileList = []
    for (var m in files) {
      var file = files[m]
      fs.renameSync(file.path, `uploads/Seller/${file.filename}.jpg`)
      file.path = `${baseURL}/Seller/${file.filename}.jpg`
      fileList.push(file)
    }
    res.send(fileList)
  }
)

module.exports = router
